<template>
  <div>
    合同列表
    <!-- 搜索框 -->
    <el-card id="search">
      <el-row>
        <el-col :span="20">
          <el-col :span="4">
            <el-select v-model="searchModel.uid" placeholder="请选择经理">
              <el-option v-for="item in createList.userList" :key="item.id" :label="item.username" :value="item.id">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4">
            <el-select v-model="searchModel.clientID" placeholder="请选择客戶">
              <el-option v-for="item in createList.clientList" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="4">
            <el-select v-model="searchModel.type1" placeholder="输选择业务类型">
              <el-option label="顾问业务" value="顾问业务"></el-option>
              <el-option label="咨询业务" value="咨询业务"></el-option>
              <el-option label="鉴证业务" value="鉴证业务"></el-option>
              <el-option label="代理业务" value="代理业务"></el-option>
              <el-option label="其他业务" value="其他业务"></el-option>
            </el-select>
          </el-col>
          <el-col :span="5">
            <el-input v-model="searchModel.keyword" placeholder="请输入合同名" clearable></el-input>
          </el-col>
          <el-col :span="3">
            <el-button type="primary" @click="getContractList" round icon="el-icon-search">查询</el-button>
          </el-col>

        </el-col>

        <el-col :span="4" align="right">
          <router-link to="/contract/addContract">
            <el-button type="success" round>新增合同</el-button>
          </router-link>
        </el-col>
      </el-row>
    </el-card>
    <!-- 搜索框 -->

    <!-- 列表 -->
    <el-card id="search">
      <template>
        <el-table :data="contractList" style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <template>
                <el-table :data="contractList" style="width: 100%" :row-class-name="tableRowClassName">
                  <el-table-column prop="date" label="日期" width="180">
                  </el-table-column>
                  <el-table-column prop="name" label="姓名" width="180">
                  </el-table-column>
                  <el-table-column prop="address" label="地址">
                  </el-table-column>
                </el-table>
              </template>
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="商品名称">
                  <span>{{ props.row.name }}</span>
                </el-form-item>
                <el-form-item label="所属店铺">
                  <span>{{ props.row.shop }}</span>
                </el-form-item>
                <el-form-item label="商品 ID">
                  <span>{{ props.row.id }}</span>
                </el-form-item>
                <el-form-item label="店铺 ID">
                  <span>{{ props.row.shopId }}</span>
                </el-form-item>
                <el-form-item label="商品分类">
                  <span>{{ props.row.category }}</span>
                </el-form-item>
                <el-form-item label="店铺地址">
                  <span>{{ props.row.address }}</span>
                </el-form-item>
                <el-form-item label="商品描述">
                  <span>{{ props.row.desc }}</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="合同编号" prop="id">
          </el-table-column>
          <el-table-column label="合同名称" prop="title">
          </el-table-column>
          <el-table-column label="客户名称" prop="client.name">
          </el-table-column>
          <el-table-column label="项目状态" prop="desc">
          </el-table-column>
          <el-table-column label="业务类型" prop="type1">
          </el-table-column>
          <el-table-column label="操作" prop="desc">
            <template slot-scope="scope">

              <router-link :to="{ path: '/contract/updateContract', query: { id: scope.row.id } }">
                <el-button type="primary" round>修改</el-button>
              </router-link>
              <router-link :to="{ path: '/contract/detailContract', query: { id: scope.row.id } }">
                <el-button type="primary" round>详情</el-button>
              </router-link>

              <el-button type="danger" round>删除</el-button>

            </template>
          </el-table-column>
        </el-table>
      </template>
    </el-card>

    <!-- 列表 -->
  </div>
</template>
  
<script>
import contractApi from '@/api/contract'
import clientApi from '@/api/client'
import UserApi from '@/api/userManage'

export default {
  name: 'contractIndex',
  data() {
    return {
      searchModel: {
        pageNo: 1,//页数
        pageSize: 10,
        pageSizes: [5, 10, 20, 50],

        keyword: '',
        type1: '',
        uid: '',
        clientID: '',
      },
      createList: {
        userList: [],
        clientList: [],
      },
      clientList: [],
      aa: [1, 2],

      contractList: [],

      tableData: [{
        id: '12987122',
        name: '好滋好味鸡蛋仔',
        category: '江浙小吃、小吃零食',
        desc: '荷兰优质淡奶，奶香浓而不腻',
        address: '上海市普陀区真北路',
        shop: '王小虎夫妻店',
        shopId: '10333'
      }, {
        id: '12987123',
        name: '好滋好味鸡蛋仔',
        category: '江浙小吃、小吃零食',
        desc: '荷兰优质淡奶，奶香浓而不腻',
        address: '上海市普陀区真北路',
        shop: '王小虎夫妻店',
        shopId: '10333'
      }, {
        id: '12987125',
        name: '好滋好味鸡蛋仔',
        category: '江浙小吃、小吃零食',
        desc: '荷兰优质淡奶，奶香浓而不腻',
        address: '上海市普陀区真北路',
        shop: '王小虎夫妻店',
        shopId: '10333'
      }, {
        id: '12987126',
        name: '好滋好味鸡蛋仔',
        category: '江浙小吃、小吃零食',
        desc: '荷兰优质淡奶，奶香浓而不腻',
        address: '上海市普陀区真北路',
        shop: '王小虎夫妻店',
        shopId: '10333'
      }],
    }
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    //获取下拉框用户
    getUidList() {
      UserApi.getManagerList().then(response => {
        this.createList.userList = response.data;
      })
    },
    //獲取客戶列表
    getClient() {
      clientApi.getAllClient().then(response => {
        this.createList.clientList = response.data.list;
      })
    },
    //获取合同列表
    getContractList() {
      contractApi.getContractList(this.searchModel).then(response => {
        this.contractList = response.data.list.data;
      })
    }
  },
  created() {
    var query = this.$route.query;

    if (query.clientID) {

      this.searchModel.clientID = query.clientID;

    }
    this.getContractList();
    this.getUidList();
    this.getClient();
  },
  watch: {
    '$route'(to, from) {
      this.searchModel.clientID = this.$route.query.clientID;
      this.getContractList();

    }
  },
}
</script>
  
<style>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>